package com.ruoyi.common.enums;

import com.ruoyi.common.core.domain.dto.CycleConfig;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 社戒社康人员类型
 */
@Getter
public enum UserDrugType {

    /**
     * 社戒
     */
    SJ("0", UserBusinessSubType.DRUG_SJSK),

    /**
     * 社康
     */
    SK("1", UserBusinessSubType.DRUG_SJSK),

    /**
     * 重点关注人员 社会面吸毒史
     */
    SHM("6", UserBusinessSubType.DRUG_ZDGZ),
    /**
     * 重点关注人员 戒断三年未复吸
     */
    JDSNWFX("11", UserBusinessSubType.DRUG_ZDGZ);


    private final String code;

    private final UserBusinessSubType userType;

    private final Map<UserEventType, CycleConfig> cycleConfigMap = new HashMap<>();

    UserDrugType(String code, UserBusinessSubType userType) {
        this.code = code;
        this.userType = userType;
        // 社戒
        if ("0".equals(code) && UserBusinessSubType.DRUG_SJSK.equals(userType)) {
            cycleConfigMap.put(UserEventType.EVENT_QD, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_TH, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_NJ, new CycleConfig(1, 2, 3));
            cycleConfigMap.put(UserEventType.EVENT_JF, new CycleConfig(3, 3, 3));
        }
        // 社康
        if ("1".equals(code) && UserBusinessSubType.DRUG_SJSK.equals(userType)) {
            cycleConfigMap.put(UserEventType.EVENT_QD, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_TH, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_NJ, new CycleConfig(2, 3, 6));
            cycleConfigMap.put(UserEventType.EVENT_JF, new CycleConfig(3, 3, 3));
        }
        // 社会面吸毒史
        if ("6".equals(code) && UserBusinessSubType.DRUG_ZDGZ.equals(userType)) {
            cycleConfigMap.put(UserEventType.EVENT_QD, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_TH, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_NJ, new CycleConfig(3, 3, 3));
            cycleConfigMap.put(UserEventType.EVENT_JF, new CycleConfig(3, 3, 3));
        }
        // 戒断三年未复吸
        if ("11".equals(code) && UserBusinessSubType.DRUG_ZDGZ.equals(userType)) {
            cycleConfigMap.put(UserEventType.EVENT_QD, new CycleConfig(1, 1, 1));
            cycleConfigMap.put(UserEventType.EVENT_TH, new CycleConfig(3, 3, 3));
            cycleConfigMap.put(UserEventType.EVENT_NJ, new CycleConfig(6, 6, 6));
            cycleConfigMap.put(UserEventType.EVENT_JF, new CycleConfig(6, 6, 6));
        }
    }

    public static UserDrugType getUserType(String code, UserBusinessSubType subType) {
        for (UserDrugType value : values()) {
            if (value.code.equals(code) && value.userType.equals(subType)) {
                return value;
            }
        }
        return null;
    }

    public String getUserType() {
        return userType.getUserType() + "_" + code;
    }

}
